#ifndef __SPARSE_MATRIX_H
#define __SPARSE_MATRIX_H

//#include "VoronoiDiagramExtended.h"

#define DEBUG 0

#define ROW_EXTENSION_SIZE 10

#define COMPARE_WITH_EXACT_SOLUTION 0

typedef struct _SparseVector SparseVector;


// voronoi cell type
template <class T> class SparseMatrix {
	
public:
	T 	**A; // values
	int **JA;  // column index of values
	int *sizeA;
	int *maxSizeA;
	
	int dimI, dimJ; // dimensions
	
public:
	// methodes
	SparseMatrix( int, int);
	~SparseMatrix();
	
	T get( int i, int j);
	int columns();
	int rows();

	void set( int i, int j, T value);
	void setLast( int i, int j, T value);

	void operator () ( int i, int j, T value);
	T operator () ( int i, int j);
	void operator = (SparseMatrix<T> *A);
	SparseMatrix<T>* copy();

	void add( int i, int j, T value);

	void resetRow( int i);

	// static methodes
	static void sparseMatrixVectorProduct( SparseMatrix<T> *A, T *b, T *x);
	static void vectorSparseMatrixProduct( T *b, SparseMatrix<T> *A, T *x);

	void printMatrix( const char* name, const char* format);
};

struct _SparseVector {
	
	float *v; // values
	int sizev;
	int *Iv;  // row index of values	
	
	int dim; // dimensions
	
	
	// methodes
	void newSparseVector( int);
	void deleteSparseVector();
	
	float get( int i);
	float set( int i);
};
	
	
#include "SparseMatrix.tcc"

#endif
